//
//  TestAPI.swift
//  LeGou
//
//  Created by lxm on 2022/11/17.
//
import Foundation

enum TestAPI {
    // 获取活动列表
    case getActivities(_ params : [String : Any], _ token : String, _ userId : Int)
    // 自动竞购
    case autoAction(_ params : [String : Any], _ token : String, _ userId : Int)
    // 获取商品列表
    case getAuctionList(_ params : [String : Any], _ token : String, _ userId : Int)
    // 竞拍详情
    case auctionDetail(_ recordId : Int, _ token : String, _ userId : Int)
    
    // 用户信息
    case userInfo(_ params : [String : Any], _ token : String, _ userId : Int)
    /// 创建将军令
    case create_auth_code(_ params : [String : Any], _ token : String, _ userId : Int)
    
    // 注册设置密码城市
    case setPsdAndCity(_ params : [String : Any], _ token : String, _ userId : Int)
    
    case inviteCode(_ params : [String : Any], _ token : String, _ userId : Int)
}

extension TestAPI: ZMApiProvider {
    func BaseUrl() -> String {
        return baseUrl
    }
    
    func urlAndMthodAndParam() -> (url: String, method: ZMHTTPMethod, params: [String : Any], body: Bool) {
        switch self {
        case .getActivities(let pa, _, _):
            return ("/api/front/ah/getActivityList", .get, pa, false)
        case .autoAction(let pa, _ , _):
            return ("/api/front/ah/beat", .post, pa, true)
        case .getAuctionList(let pa, _ , _):
            return ("/api/front/ah/getGoods", .get, pa, false)
        case .auctionDetail(let recordId, _, _):
            return ("/api/front/ah/detail/\(recordId)", .get, [:], false)
        case .userInfo(let pa, _, _):
            return ("/api/front/user", .get, pa, false)
        case .create_auth_code(let pa, _, _):
            return ("/api/front/amateur/createAuthCode", .get, pa, false)
        case .setPsdAndCity(let pa, _, _):
            return ("/api/front/user/pwd/set", .post, pa, true)
        case .inviteCode(let pa, _, _):
            return ("/api/front/user/bindSpread", .post, pa, true)
            
        }
    }
    
    func HTTPHeader() -> ZMHTTPHeaders? {
        var reHeader = AppHelper.reqeustHeader()
        switch self {
            case .autoAction(_ , let token, let userId),
                .getAuctionList(_ , let token, let userId),
                .auctionDetail(_ , let token, let userId),
                .getActivities(_ , let token, let userId),
                .userInfo(_ , let token, let userId),
                .create_auth_code(_ , let token, let userId),
                .setPsdAndCity(_ , let token, let userId),
                .inviteCode(_ , let token, let userId):
            reHeader["userId"] = "\(userId)"
            reHeader["Authori-zation"] = "\(token)"
        }
        return reHeader
    }
    
    func UpLoadData() -> [Data]? {
        return nil
    }
    
    func ParamInBody() -> Bool {
        switch self {
//            return true
        default:
            return false
        }
    }
}
